package com.fl.proyect_softmedic;

import com.example.proyect_softmedic.R;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Viewdetails_day_schedulle extends Activity {
	
	//variables para el listado de agendas
    private TableLayout tabla;
    private TableLayout cabecera4;
    private TableRow.LayoutParams layoutFila;
    private TableRow.LayoutParams layoutLong;
    private TableRow.LayoutParams layoutDefault;
    private Resources rs;
    private EditText getidschedulle;
    private TableRow fila;
    private int role = 1;

    //boton para regresar al menu de inicio
    private Button btnstart;

	@SuppressLint("CutPasteId")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_viewdetails_day_schedulle);
		
		btnstart = (Button)findViewById(R.id.btnGoStart4);
		btnstart.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub	
				
				if(role==1){
					Intent i = new Intent(Viewdetails_day_schedulle.this, Activity_medic.class);
					startActivity(i);
				}else{
					//debe ir al menu de recepcionitas
				}
					
			}
		});
		
		
		//asignacion variables lista de agendas
        rs = this.getResources();
        tabla = (TableLayout)findViewById(R.id.tabla5);
        cabecera4 = (TableLayout)findViewById(R.id.cabecera4);
        layoutFila = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
        layoutLong = new TableRow.LayoutParams(200,TableRow.LayoutParams.WRAP_CONTENT);
        layoutDefault = new TableRow.LayoutParams(160,TableRow.LayoutParams.WRAP_CONTENT);
  
        //caja de texto para almacenar el id de la cita seleccionada por el usuario
        getidschedulle = (EditText)findViewById(R.id.editNum4);
        getidschedulle.setFocusable(false);
        getidschedulle.setVisibility(View.INVISIBLE);
        getidschedulle.setKeyListener(null);
        

        addheader();
        setregisters();          
	}
	
	
	
	//muestra la cabecera de la tabla
	public void addheader(){
	//se definen los objetos a utilizar	
	TableRow fila;		
	TextView txt_date;
	TextView txtIdate_week;
	TextView txtcount_quotes;
	TextView txtdetails;
	
	//se asigna el valor del objeto fila y se le asigna el layout fila
	 fila = new TableRow(this);
	 fila.setLayoutParams(layoutFila);
	 
	 //se asignan valores a los objetos creados previamente

	 txt_date = new TextView(this);
	 txtIdate_week = new TextView(this);
	 txtcount_quotes = new TextView(this);
	 txtdetails = new TextView(this);

	//se asigna propiedades a el objeto fecha
	 txt_date.setText(rs.getString(R.string.txtvdate_quote));
	 txt_date.setGravity(Gravity.CENTER_HORIZONTAL);
	 txt_date.setTextAppearance(this,R.style.etiqueta);
	 txt_date.setBackgroundResource(R.drawable.styles_edittext);
	 txt_date.setLayoutParams(layoutLong);
	 
	//se asigna propiedades a el objeto dia de la semana
	 txtIdate_week.setText(rs.getString(R.string.txtvday_week));
	 txtIdate_week.setGravity(Gravity.CENTER_HORIZONTAL);
	 txtIdate_week.setTextAppearance(this,R.style.etiqueta);
	 txtIdate_week.setBackgroundResource(R.drawable.styles_edittext);
	 txtIdate_week.setLayoutParams(layoutLong);
	 
	 //se asigna propiedades a el objeto para mostra la cantidad de citas del dia
	 txtcount_quotes.setText(rs.getString(R.string.txtv_count_quotes));
	 txtcount_quotes.setGravity(Gravity.CENTER_HORIZONTAL);
	 txtcount_quotes.setTextAppearance(this,R.style.etiqueta);
	 txtcount_quotes.setBackgroundResource(R.drawable.styles_edittext);
	 txtcount_quotes.setLayoutParams(layoutLong);
	 
	 
	 //se asigna propiedades a el objeto para mostra la cantidad de citas del dia
	 txtdetails.setText(rs.getString(R.string.txtv_view_details));
	 txtdetails.setGravity(Gravity.CENTER_HORIZONTAL);
	 txtdetails.setTextAppearance(this,R.style.etiqueta);
	 txtdetails.setBackgroundResource(R.drawable.styles_edittext);
	 //txtdetails.setLayoutParams(layoutLong);
	 
	 

	 // se asignan cada uno de los objetos a la fila
	 fila.addView(txt_date);
	 fila.addView(txtIdate_week);
	 fila.addView(txtcount_quotes);
	 fila.addView(txtdetails);
	 cabecera4.addView(fila);
	 }
	
	//muestra los registros 
	public void setregisters(){
		
		for(int i = 1; i <= 31; i++){
		 
		 TextView txtdate;
	     TextView txtday_week;
	     TextView txtcount; 
	     Button button;
         fila = new TableRow(this);
         fila.setLayoutParams(layoutFila);
         txtdate = new TextView(this);	         
         txtday_week = new TextView(this);
         txtcount = new TextView(this);
         button = new Button(this);
         
         //variables para almacenar los datos a mostrar desde la consulta de los dias agendados
         String date1 = "09/09/2013";
         String dayweek = "Lunes";
         String countquptes = "9";
         
         txtdate.setText(date1);
         txtdate.setGravity(Gravity.CENTER_HORIZONTAL);
         txtdate.setTextAppearance(this,R.style.etiqueta);
         txtdate.setBackgroundResource(R.drawable.styles_edittext);
         txtdate.setLayoutParams(layoutLong);
         
         txtday_week.setText(dayweek);
         txtday_week.setGravity(Gravity.CENTER_HORIZONTAL);
         txtday_week.setTextAppearance(this,R.style.etiqueta);
         txtday_week.setBackgroundResource(R.drawable.tabla_celda);
         txtday_week.setLayoutParams(layoutLong);
         
         txtcount.setText(countquptes);
         txtcount.setGravity(Gravity.CENTER_HORIZONTAL);
         txtcount.setTextAppearance(this,R.style.etiqueta);
         txtcount.setBackgroundResource(R.drawable.tabla_celda);
         txtcount.setLayoutParams(layoutDefault);
         
         
         button.setText(rs.getString(R.string.txtv_query));
         button.setGravity(Gravity.CENTER_HORIZONTAL);
         button.setBackgroundResource(R.drawable.styles_edittext);
         button.setLayoutParams(layoutDefault);
         button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(Viewdetails_day_schedulle.this, Viewdetails_schedulle_name_patient.class);
				startActivity(i);				
			}
		});
        
         fila.addView(txtdate);        
         fila.addView(txtday_week);
         fila.addView(txtcount);
         fila.addView(button);
         tabla.addView(fila);
         
		}
	}

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.viewdetails_day_schedulle, menu);
		return true;
	}

}
